package fun.werfamily.wf.auth.core.controller;

import fun.werfamily.wf.auth.core.dto.UserLoginReqDTO;
import fun.werfamily.wf.auth.core.dto.UserTokenDTO;
import fun.werfamily.wf.auth.core.dto.VerifyCodeReqDTO;
import fun.werfamily.wf.auth.core.service.AuthService;
import fun.werfamily.wf.base.annotation.MustLogin;
import fun.werfamily.wf.base.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: Mr.WenMing Zhang
 * @Date: 2022/07/28 14:44
 * @Description:
 **/
@RestController
@Api("用户模块")
@RequestMapping("/auth")
public class LoginController {
    @Resource
    private AuthService authService;

    @ApiOperation("手机号登录接口")
    @PostMapping("/username/login")
    @MustLogin(value = false)
    public Result<UserTokenDTO> login(@Validated @RequestBody UserLoginReqDTO userLoginReqDTO) {
        return Result.success(authService.userNameLogin(userLoginReqDTO));
    }

    @ApiOperation("手机号验证码登录接口")
    @PostMapping("/verify/login")
    @MustLogin(value = false)
    public Result<UserTokenDTO> verifyLogin(@Validated @RequestBody VerifyCodeReqDTO verifyCodeReqDTO) {
        return Result.success(authService.verifyLogin(verifyCodeReqDTO));
    }

    @ApiOperation("退出接口")
    @PostMapping("/logout")
    @MustLogin(value = false)
    public Result<Boolean> logout(HttpServletRequest request) {
        return Result.success(authService.logout(request));
    }
}
